import type { IConfigBase, IRule } from '../base'

/** 搜索组件元素类型 */
type ISearchType = 'input' | 'select' | 'date-picker' | 'radio' | 'custom'

interface IFormBase {
  type?: ISearchType
  /** 搜索属性 */
  prop?: string
  /** 搜索标签 */
  label?: string
  /** 元素占位宽度比例 */
  elColSpan?: number
  /** 初始值 */
  initialValue?: string | number
}

interface IFormInput extends IFormBase {
  type: 'input'
  /** 搜索占位符 */
  placeholder?: string
  /** 初始化值 */
  initialValue?: string | number
  /** 是否可清除 */
  isClearable?: boolean

  disabled?: boolean

  rules?: IRule[] | IRule
}

interface IFormDatePicker extends IFormBase {
  type: 'date-picker'
  rangeSeparator?: string
}

interface IFormSelect extends IFormBase {
  type: 'select'
  /** 搜索占位符 */
  placeholder?: string
  /** 是否可清除 */
  isClearable?: boolean
  /** 选项值 */
  options: { label: string; value: string | number | boolean }[]
}

interface IFormRadio extends IFormBase {
  type: 'radio'
  /** 选项值 */
  options: { label: string; value: string | number | boolean }[]
  rules?: IRule[] | IRule
}

interface IFormCoustom extends IFormBase {
  type: 'custom'
  slotName: string
}

/** 搜索组件元素配置 */
type IFormItem =
  | IFormInput
  | IFormDatePicker
  | IFormSelect
  | IFormCoustom
  | IFormRadio

/** 搜索组件配置 */
export type IFormConfig = IConfigBase<IFormItem>
